home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # isdn.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: isdn-setup.frm,v 1.40 1997/07/15 20:10:18 shotes Exp $
-
- # currently allowed only one switch type (and pair of SPID #'s),
- # but can have multiple connection names (and phone numbers).
- # this is to remove ambiguity that entries in isdnd.options know
- # nothing of connection names. code will comment out conflicting
- # entries.
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $confS = "/etc/uucp/Systems";
- $conf = "/etc/config/isdnd.options";
- $dummy = "/etc/config/isdnd.options.tmp";
- $pwdfile = "/etc/passwd";
- $myname = "isdn-setup.cgi";
- $title = "ISDN Setup";
-
- if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
- else { $br_index = 0; }
-
- $js =
- "br_index = $br_index;
- $js_standard
- $js_error_box
- $js_phone
- $js_hostname
- function checkForm(form) {
- if (form.isdns[br_index].checked) {
- if (!testHostname(form.nme, form.nme.value, \"connection name\", 0)) return (false);
- if (!testPhone(form.phone)) return (false);
- if (!testSwitch(form)) return (false);
- } return (true);
- }
- function testSwitch(form) {
- Ctrl = form.switchtype; selnum = Ctrl.selectedIndex;
- word1 = form.spid1.value; word2 = form.spid2.value;
- selected = Ctrl.options[selnum].text;
- if (selected == \"DMS100\" || selected == \"NI1\") {
- if(word1 == \"\" || word2 == \"\") {
- errorBox (Ctrl, \"Two SPID numbers required for \\nswitch type \" + selected);
- return (false);
- }
- for(i=0; i < word1.length; i++) {
- if (! checkInt_c(word1.charAt(i), 10)) {
- errorBox (Ctrl, \"Invalid SPID number: \" + word1);
- return (false);
- }
- }
- for(i=0; i < word2.length; i++) {
- if (! checkInt_c(word2.charAt(i), 10)) {
- errorBox (Ctrl, \"Invalid SPID number: \" + word2);
- return (false);
- }
- }
- } return (true);
- }";
-
-
- print "Content-type: text/html\n\n";
-
- @types = ('DMS100','NI1','5ESS','NTT','NET3/DSS1','1TR6','VN3','TPH');
-
- &get_fields;
-
- &getInfo;
-
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- if ($fld{"doit"} eq "Ok") {
- if ($fld{'isdns'} eq "Yes") { &formValidation; };
- &edit;
- &getInfo;
- &putValues;
- if (!$message) { $message = "No change."; }
- } else { &putValues; }
-
- if (-e "/usr/etc/isdnd") { &generic; }
- else {
- &title_block($title);
- &header_block($title);
- print "<i>ISDN software not installed. Install subsystem </i><b>isdn_eoe.sw</b><i>
- from the distribution CD (6.2 or 6.3), or for OS 6.4 please install
- the appropriate patch.</i>";
- }
-
- sub formValidation {
- &error("Invalid telephone number entry.") if &check_phone($fld{'phone'});
- &error("Invalid connection name.") if $fld{'nme'} =~ /$METACHARS/o;
-
- if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
- &error("Invalid SPID number: $fld{'spid1'}.")
- if ($fld{'spid1'} =~ /[^0-9]/);
- &error("Invalid SPID number: $fld{'spid2'}.")
- if ($fld{'spid2'} =~ /[^0-9]/);
- if (!$fld{'spid1'})
- { &error("Two SPID numbers required for this switch."); }
- if (!$fld{'spid2'})
- { &error("Two SPID numbers required for this switch."); }
- }
- }
-
- sub error {
- &error_block($_[0]);
- %val = %fld;
- &generic;
- exit 0;
- }
-
- sub edit {
- if ($fld{'isdns'} ne $isdns) { &editStatus; }
- if ($fld{'isdns'} eq "Yes") { &writeFile; }
- }
-
- sub writeFile {
- if (&checkOpChange) {
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- $line = $_;
- if (substr($_,0,2) ne "-t") { print OUT $_; }
- else { print OUT "# $line"; }
- }
- if ($fld{'switchtype'} eq "NET3/DSS1") {
- print OUT "-t NET3";
- } else {
- print OUT "-t $fld{'switchtype'}";
- }
- if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
- print OUT " -s $fld{'spid1'} -s $fld{'spid2'}";
- }
- print OUT "\n";
- close(OUT);
- close(IN);
- rename($dummy,$conf);
- }
-
- $fld{'phone'} =~ s/-//g;
- if (&checkSyChange) {
- open(IN,"< $confS");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if (substr($items[0],0,1) eq '#') { print OUT $_; next; }
- if ($items[0] ne $nme || $items[2] ne 'ISDN') { print OUT $_; }
- else { print OUT "# $_"; }
- }
- if ($fld{'switchtype'} eq "NET3/DSS1") {
- print OUT
- qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[64]$fld{'phone'} CONNECTED\n|;
- } else {
- print OUT
- qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[56]$fld{'phone'} CONNECTED\n|;
- }
- close(OUT);
- close(IN);
- chmod 0600, $confS;
- rename($dummy,$confS);
- chmod 0400, $confS;
- }
- $message .= "Parameters edited.";
- }
-
- sub checkSyChange {
- if ($fld{'nme'} ne $nme || $fld{'phone'} ne $phone) { return 1; }
- return 0;
- }
-
- sub checkOpChange {
- if ($fld{'switchtype'} ne $swType) { return 1; }
- if ($swNum > 1) { return 0; }
- if ($fld{'spid1'} ne $spid[0]) { return 1; }
- if ($fld{'spid2'} ne $spid[1]) { return 1; }
- return 0;
- }
-
- sub editStatus {
- if ($fld{'isdns'} eq "Yes") {
- system("/etc/chkconfig", "isdnd", "on");
- `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
- `/bin/csh -c '(/bin/csh /etc/init.d/isdnd start) >&! /dev/null'`;
- $message = "ISDN enabled. ";
- }
- else {
- system("/etc/chkconfig", "isdnd", "off");
- `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
- $message = "ISDN disabled. ";
- }
- }
-
- sub putValues {
- $val{'isdns'} = $isdns;
- $val{'nme'} = $nme;
- $val{'phone'} = $phone;
- $val{'switchtype'} = $swType;
- $val{'spid1'} = $spid[0];
- $val{'spid2'} = $spid[1];
- }
-
- sub generic {
- &js_title_block($title,$js);
- &header_block($title);
-
- print "<i>$message</i>";
-
- print "<form name=\"StandardForm\" action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<center><table cellpadding=5 width=450>\n";
-
- print "<tr><th align=left>Enable ISDN:</th><th align=left>";
- print &radio('isdns',$val{'isdns'},"Yes","No");
- print "</th></tr>";
-
- print "<tr><th align=left>Connection name for host answering calls:
- </th><th align=left>";
- print &text('nme',$val{'nme'},20);
- print "</th></tr>";
-
- print "<tr><th align=left>Phone number for host answering calls:
- </th><th align=left>";
- print &text('phone',$val{'phone'},20);
- print "</th></tr>";
-
- print "<tr><th align=left>Type of switch used for connections:
- </th><th align=left>";
- print &select('switchtype',$val{'switchtype'},'DMS100','NI1','5ESS',
- 'NTT','NET3/DSS1','1TR6','VN3','TPH');
- print "</th></tr>\n";
-
- print "<tr><th align=left>SPID #1:</th><th align=left>";
- print &text('spid1',$val{'spid1'},20);
- print "</th></tr>\n";
-
- print "<tr><th align=left>SPID #2:</th><th align=left>";
- print &text('spid2',$val{'spid2'},20);
- print "</th></tr></table></center><br>\n";
-
- print "<i>Note: SPID numbers are required only for switch types\n";
- print "DMS100 and NI1.</i><br><br>\n";
-
- print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getInfo {
- $isdns = &get_config("isdnd");
- $spid[0] = $spid[1] = "";
-
- open(IN,"< $conf");
- while(<IN>) {
- $line = $_;
- if (substr($line,0,2) eq "-t") {
- @args = split(/\s+/,$line);
- $swType = $args[1];
- if ($swType eq "NET3") { $swType = "NET3/DSS1"; }
- $countSPID = 0;
- for ($i=0;$i<=$#args;$i++) {
- if ($args[$i] eq "-s") {
- $spid[$countSPID] = $args[$i+1];
- $countSPID++;
- }
- }
- }
- }
- close(IN);
-
- open(IN,"< $confS");
- while(<IN>) {
- @items = split(/\s+/);
- if (substr($items[0],0,1) eq '#') { next; }
- if ($items[2] eq 'ISDN') {
- $nme = $items[0];
- $items[6] =~ /.*\](\w+)$/;
- $phone = $1;
- }
- }
- close(IN);
- }
-